home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Grafik & Text
/
Alpha
/
Tcl
/
SystemCode
/
strings.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
3KB
|
89 lines
#
# strings.tcl (Mark Nagata and Tom Scavo)
#
proc setPrefix {} {
global prefixString
if {[catch {prompt "New Prefix String:" $prefixString} res] == 1} return
set prefixString $res
}
proc setSuffix {} {
global suffixString
if {[catch {prompt "New Suffix String:" $suffixString} res] == 1} return
set suffixString $res
}
proc insertSuffix {} {doSuffix insert}
proc removeSuffix {} {doSuffix remove}
proc doSuffix {which} {
global suffixString
set pts [getEndpts]
set start [lindex $pts 0]
set end [lindex $pts 1]
set start [lineStart $start]
set end [nextLineStart [expr $end-1]]
set text [getText $start $end]
set text [doSuffixText $which $suffixString $text]
replaceText $start $end $text
select $start [getPos]
}
# Returns a modified text string if the string $text is non-null,
# and the null string otherwise. The argument 'operation' is a
# string directing 'doSuffixText' to either "insert" or "remove"
# $suffixString to/from each line of $text.
proc doSuffixText {operation suffixString text} {
if {$text == ""} {return ""}
set suff [quoteExpr $suffixString]
if {$operation == "insert"} then {
set str ${suffixString}\r
regsub -all \r $text $str text
} elseif {$operation == "remove"} then {
set str ${suff}\r
regsub -all $str $text \r text
}
return $text
}
proc commentLine {} {insertPrefix}
proc uncommentLine {} {removePrefix}
proc insertPrefix {} {doPrefix insert}
proc removePrefix {} {doPrefix remove}
proc doPrefix {which} {
global prefixString
if {[set start [getPos]] == [set end [selEnd]]} {
set end [nextLineStart $start]
}
set start [lineStart $start]
set text [getText $start $end]
replaceText $start $end [doPrefixText $which $prefixString $text]
select $start [getPos]
}
# Returns a modified text string if the string $text is non-null,
# and the null string otherwise. The argument 'operation' is a
# string directing 'doPrefixText' to either "insert" or "remove"
# $prefixString to/from each line of $text. See latexEngine.tcl
# for an example.
proc doPrefixText {operation prefixString text} {
if {$text == ""} {return ""}
set pref [quoteExpr $prefixString]
if {$operation == "insert"} then {
set trailChar ""
set textLen [string length $text]
if {[string index $text [expr $textLen-1]] == "\r"} then {
set text [string range $text 0 [expr $textLen-2]]
set trailChar "\r"
}
set str \r$prefixString
regsub -all \r $text $str text
return $prefixString$text$trailChar
} elseif {$operation == "remove"} then {
regsub -all \r$pref $text \r text
regsub ^$pref $text "" text
return $text
}
}